(function () {
  const id = location.search.substring(4);
  axios.defaults.baseURL = 'http://124.223.14.236:3001/api'

  // ===============> 获取菜单详情
  fun()
  async function fun() {
    const { data: { data: res } } = await axios.get(`/recipe/${id}`)
    console.log(res)
    const img = 'http://124.223.14.236:3001/public/' + res.img
    document.querySelector('.container .left img').src = img
    document.querySelector('.container .right h3').innerHTML = res.name
    document.querySelector('.container .right p').innerHTML = res.description


    // ===============>渲染美食列表
    // axios({
    //   method: 'GET',
    //   url: cmurl + '/api/recipeInfo/',
    //   params: {
    //     recipe_id: id,
    //   },
    // }).then(function (result) {
    //   const list = result.data.data;
    //   if (list.length) {
    //     let listStr = list
    //       .map((item, index) => {
    //         const { img, title, id } = item;
    //         return `
    //       <li>
    //         <a href="food_detail.html?id=${id}">
    //           <img src=${cmurl + '/public/' + img} alt="" />
    //           <h3>${title}</h3>
    //         </a>
    //       </li>
    //     `;
    //       })
    //       .join('');
    //     document.querySelector('#list-box').innerHTML = listStr;
    //   } else {
    //     document.body.innerHTML += '<p class="noinfo">没有美食哦...</p>';
    //   }
    // });
    const { data: re } = await axios.get(`/recipeInfo`, {
      params: {
        recipe_id: id,
      }
    })
    // console.log(re)
    const list = re.data
    // console.log(list)
    if (list.length) {
      const listStr = list.map((item, index) => {
        const { img, title, id } = item
        const cmurl = 'http://124.223.14.236:3001/public/'
        return `
          <li>
            <a href="./detail.html?id=${id}">
              <img src=${cmurl + img} alt="" />
              <h3>${title}</h3>
            </a>
          </li>
        `
      }).join('')
      console.log(listStr)
      document.querySelector('#list-box').innerHTML = listStr
    } else {
      document.body.innerHTML += '<p class="noinfo">没有美食哦...</p>'
    }
  }
})()